//
// Created by yewei on 2022/12/31.
//
#include <bits/stdc++.h>

using namespace std;

int main() {
    freopen("../input.txt", "r", stdin);
    int n,k;
    cin>>n>>k;
    unordered_map<int,int> m;
    int tmp;
    for(int i=1;i<=n;i++){
        cin>>tmp;
        m[tmp] = i;
    }
    int now = 1;
    int cnt=0;
    int target;
    for(int i=1;i<=k;i++){
        target = i;
        target %= n;
        if(target==0) target=n;
        cnt += (m[target]+n-now)%n;
        now = m[target];
    }
    cout<<cnt;
}
